﻿namespace Azalea.ORMap
{
    public class SqlDelete : ISqlDelete
    {
        private readonly CommandBuilder _cmdBuilder;
        private string _tableName;

        public SqlDelete(CommandBuilder cmdBuilder)
        {
            _cmdBuilder = cmdBuilder;
        }

        #region ISqlDelete Members

        public ISqlDelete Table(string tableName)
        {
            _tableName = tableName;
            return this;
        }

        public ISqlWhere Where()
        {
            GenerateSql();

            return new SqlWhere(_cmdBuilder, _tableName);
        }

        public ICommandBuilder Done()
        {
            GenerateSql();

            return _cmdBuilder;
        }

        #endregion

        private void GenerateSql()
        {
            _cmdBuilder._sqlBuilder.Append("delete from ")
                .Append(_cmdBuilder.QuotingKeyword(_tableName));
        }
    }
}